package com.homegoods.orderinfodetail.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.flexbox.FlexboxLayoutManager;
import com.kedll.library.adapter.MultiTypeAdapter;

/**
 * @author QiQi
 * @ClassName: ShopDetailAdapter
 * @date 2018/9/26
 * @description
 */
public class ShopDetailAdapter extends MultiTypeAdapter {
    private int itemWidth;

    public ShopDetailAdapter(Context context, int itemCount, int padding) {
        itemWidth = (context.getResources().getDisplayMetrics().widthPixels - padding) / itemCount;
    }

    @Override
    public void onBindViewHolder(@NonNull ItemViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        View view = holder.itemView;
        ViewGroup.LayoutParams lp = view.getLayoutParams();
        if (lp instanceof FlexboxLayoutManager.LayoutParams) {
            FlexboxLayoutManager.LayoutParams flexboxLp = (FlexboxLayoutManager.LayoutParams) lp;
            if (position == getItemCount() - 1 || position < 3) {
                flexboxLp.setWrapBefore(true);
            } else {
                flexboxLp.setMaxWidth(itemWidth);
                flexboxLp.setFlexGrow(1.0f);
            }
        }

    }
}
